<template>
  <detail>
    <detail-item :label="$t('vehicleModel')" :content="recordData.modelCode?recordData.modelCode:'-'"  />
    <detail-item :label="$t('partNumber')" :content="recordData.ecu.ecuModuleId"  />
    <detail-item :label="$t('partName')" :content="recordData.ecu.name"  />
    <detail-item :label="$t('versionName')" :content="recordData.name"  />
    <detail-item :label="$t('versionCode')" :content="recordData.code"  />
    <detail-item :label="$t('softwareCoding')" :content="recordData.softwareCode"  />
    <detail-item :label="$t('dependencyVersion')" :content="recordData.dependenceVersion"  />
    <detail-item :label="$t('releaseNote')" >
      <a @click="showRelease()" class="Inforcontent">{{ $t('view') }}</a>
    </detail-item>
    <detail-item :label="$t('configFileVersion')"
                 :content="recordData.configVersionName ? (recordData.configVersionName + '-' + (configVersionType === 'TEST' ? '测试版' : configVersionType === 'PROD' ? '定版' : '')) : '-'" />
    <detail-item :label="$t('hardVersion')" :content="recordData.hardVersion?recordData.hardVersion:'-'"  />
    <detail-item :label="$t('hardVersionDate')" :content="recordData.hardVersionDate?$options.filters.dayjs(recordData.hardVersionDate):'-'"  />
    <detail-item :label="$t('timeOfCreation')" :content="$options.filters.moment(recordData.createTime)"  />
    <detail-item :label="$t('creator')" :content="recordData.createBy"  />   
    <detail-item :label="$t('dllFileClassName')" :content="dllName?dllName:'-'" />
    <!-- 拿到参数后修改 -->
    <detail-item  label="表单类型" v-if="recordData.formType==='AUTO'"  :content="recordData.formType==='AUTO'?'自动创建':'手动创建'"  />   
    <detail-item v-if="recordData.formType==='AUTO'" label="SVN日期" :content="recordData.svnDate?recordData.svnDate:'-'"  />   

    <view-release-note
      ref="releaseNote"
      :width="600"
      :releaseNotes="releaseNotes || {}"
    ></view-release-note>
  </detail>
</template>
<script>
import TableEllipsis from '@/components/Ellipsis/TableEllipsis'
import ViewReleaseNote from '@/views/components/ViewReleaseNote'
import DetailItem from '@/components/detail/detailItem'
import Detail from '@/components/detail'

import { mapState } from 'vuex'
export default {
  name: 'VersionInfor',
  components: {
    Detail,
    DetailItem,
    TableEllipsis,
    ViewReleaseNote
  },
  props: {
    recordData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  computed: {
    ...mapState({
      instantUpdateTime: (state) => state.app.instantUpdateTime
    })
  },
  data () {
    return {
      dllName: '',
      fileUrl: '',
      fileName: '',
      releaseNotes: null,
      configVersionType: ''
    }
  },
  watch: {
    instantUpdateTime: {
      handler () {
        this.getVersionInfor()
      },
      immediate: true
    }
  },
  methods: {
    getConfigVersionType(){
      if (!this.recordData.configVersionId) {
        return;
      }
      this.$api.configFileDetail({ id: this.recordData.configVersionId }).then((res) => {
        this.configVersionType = res.data.versionType
      });
    },
    showRelease () {
      this.$refs.releaseNote.visible = true
    },
    getVersionInfor () {
      const vm = this
      vm.$api.versionInfor({ id: this.recordData.id }).then(response => {
        this.fileName = response.data.materialFile && response.data.materialFile.name
        this.dllName = response.data.dllName
        this.fileUrl = response.data.materialFile && response.data.materialFile.url
        this.releaseNotes = {
          description: response.data.description,
          functionAddition: response.data.functionAddition,
          functionOptimization: response.data.functionOptimization,
          acknowledgements: response.data.acknowledgements
        }
        this.getConfigVersionType();
      })
    }
  }

}
</script>

